
// 时间数字前加0
function formatNumber(n) {
	n = n.toString()
	return n[1] ? n : '0' + n
}

// 获取当前时间并转换
function getNowTime() {
	let date = new Date()
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate()
	const hour = date.getHours()
	const minute = date.getMinutes()
	const second = date.getSeconds()
	return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatPrice(n) {
	if (n == 0) {
		return "0.00"
	}
	if (n == null || n == "") {
		return n
	}
	let number = n.toString()
	if (number.indexOf(".") > 0) {
		let arr = number.split('.')
		let len = arr[1].length
		if (len == 1) {
			number = arr[0] + '.' + arr[1] + '0'
		} else if (len == 2) {
			number = number
		} else if (len > 2) {
			number = arr[0] + '.' + arr[1].slice(0, 2)
		}
	} else {
		number = number + ".00"
	}
	return number
}

export default {
	getNowTime,
	formatNumber,
	formatPrice
}
// export default getNowTime

// export default formatPrice